package jmcnet.libcommun.servlet;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;

public class RequestWrapper extends HttpServletRequestWrapper {
	private String servletPath=null;
	private String method=null;
	private String sessionId=null;
	
	public RequestWrapper(HttpServletRequest request) {
		super(request);
		this.servletPath = request.getServletPath();
		this.method = request.getMethod();
		this.sessionId = request.getRequestedSessionId();
	}
	
	public RequestWrapper(HttpServletRequest request, String servletPath, String method, String sessionId) {
		super(request);
		this.servletPath = servletPath;
		this.method = method;
		this.sessionId = sessionId;
	}
	
	public RequestWrapper(HttpServletRequest request, String servletPath, String method) {
		super(request);
		this.servletPath = servletPath;
		this.method = method;
		this.sessionId = request.getRequestedSessionId();
	}
	
	public void setServletPath(String servletPath) {
		this.servletPath = servletPath;
	}
	
	public void setMethod(String method) {
		this.method = method;
	}
	
	@Override
	public String getMethod() {
		return this.method;
	}
	
	@Override
	public String getServletPath() {
		return this.servletPath;
	}
	
	@Override
	public StringBuffer getRequestURL() {
		return new StringBuffer().append(getScheme()).append("://").
			append(getServerName()).append(":").append(getServerPort()).append(getRequestURI());
	}
	
	@Override
	public String getRequestURI() {
		return getContextPath()+getServletPath();
	}
	
	@Override
	public String getRequestedSessionId() {
		return sessionId;
	}

	@Override
	public boolean isRequestedSessionIdValid() {
		return sessionId != null;
	}
	
	public void removeRequestedSessionId() {
		this.sessionId = null;
	}
	
	public void setRequestedSessionId(String sessionId) {
		this.sessionId = sessionId;
	}
}
